package com.gj.my_aop.resp;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum ReturnCodeEnum {
    //枚举值
    RC999("999","操作XXX失败"),
    RC200("200","success");


    private final String code;
    private final String message;

    //构造
    private ReturnCodeEnum(String code,String message){
        this.code = code;
        this.message = message;
    }

    //遍历枚举
    public static ReturnCodeEnum getReturnCodeEnum(String code){
        for (ReturnCodeEnum codeEnum : ReturnCodeEnum.values()) {
            if (codeEnum.getCode().equalsIgnoreCase(code)){
                return codeEnum;
            }
        }
        return null;
    }
    //遍历枚举v2
    public static ReturnCodeEnum getReturnCodeEnumV2(String code){
        return Arrays.stream(ReturnCodeEnum.values())
                .filter(element->element.getCode().equalsIgnoreCase(code)).findFirst().orElse(null);
    }
}
